app_Ctrl.controller('HomeCtrl', function( $ionicPopup,mineModule,$cordovaToast,md5,Storage,$ionicLoading,loginModule,$ionicPopover,$scope,Common,$state,$ionicModal,$translate,homeModule,$ionicSlideBoxDelegate) {
  // wifi
  $scope.go_wifi = function(){
    //判断用户是否对登录；
    if(Storage.ls_get("user_infos")){//登录过。可直接链接Wi-Fi；
      cordova.InAppBrowser.open('http://api.sh-centurylink.cn/404/404.html', '_system', 'location=yes');
    }else{//没有登录，提示先去登录
      $ionicPopup.alert({
        title: '温馨提示',
        template: '您必须登录后才能使用!'
      });
    }
  }

  //获取会员的等级(要登录)
  $scope.get_member_coupon = function(){
    var phone = JSON.parse(Storage.ls_get("user_infos")).memberuuid;
    var params = {
      memberUUID:phone
    }
    mineModule.http("getMember",params).then(function(data){
      // console.log("取到优惠券的数量："+JSON.stringify(data));
      if(data.code = 10000){
        
        //获取优惠券的数量；
        //获取会员等级（金卡、铂金、钻石 /积分/会员卡号）、
        $scope.card_grade = data.info.cardName;//卡的等级
        $scope.card_num = data.info.cardNo;//卡号
        $scope.integral = data.info.usableBonus;//可用积分
        $scope.phone =  data.info.mobile;
      }else{
        alert("获取信息出错了！")
      }
    })
  }
//停车场功能（要登录）
  $scope.parking_space = "——";
  $scope.car_num = 0;
  $scope.get_park_info = function(){
    if(Storage.ls_get("user_infos")){
      var params = {
        c_member_id:JSON.parse(Storage.ls_get("user_infos")).m_id,
      }
      mineModule.park_serve("park",params).then(function(res){
        console.log("获取到停车场的信息："+JSON.stringify(res));
        $scope.statu_count++
        //剩余车位状态码为1的时候，说明停车场的接口出现问题；
        if(res.leftPlace){//停车位空余数量；
          $scope.parking_space = res.leftPlace;
        }else{
          $scope.parking_space = "——";
        }
        //左边车牌显示；
        $scope.isoutpark = true;
        if(res.resCode == 0){//已添加过车牌（里面区分已入场跟未入场的状态）
          //遍历车牌数组 找出有入场状态的车牌；
          // if(res.cars.length > 0){
          for(var i = 0 ;i<res.cars.length;i++){
            if(res.cars[i].inpark == 1){
              $scope.show_plate = res.cars[i].c_member_car;
              $scope.car_num = res.cars.length;
              $scope.isoutpark = false;
              break;
            }else{
              $scope.show_plate = res.cars[0].c_member_car;
              $scope.car_num = res.cars.length;
              // $scope.isoutpark = true;
            }
          }
        }else if(res.resCode == 1){//未添加车牌（显示添加车牌）
          $scope.car_num = 0;
          $scope.show_plate = '添加车牌';
          // $scope.isoutpark = true;
        }
      })
    }
  }
 
//优惠卷模块(需要登录)；
  $scope.get_mine_coupon = function(){
  	$scope.memberUUID = JSON.parse(Storage.ls_get("user_infos")).memberuuid;
  	var params = {page:1,rows:5,memberUUID: $scope.memberUUID,type:1}//ke yong quan
  	mineModule.http('getCoupon',params).then(function(res){
  		// console.log("获取到要展示的个人券："+JSON.stringify(res));
  		if(res.code == 10000){
  			$scope.show_items = res.data.list
  			//mySwiper
				var swiper = new Swiper('.swiper-container', {
					pagination: '.swiper-pagination',
					observer:true,
					effect: 'coverflow',
					grabCursor: true,
					centeredSlides: true,
					slidesPerView: 'auto',
				    coverflow: {
					    rotate: 50,
					    stretch: 0,
					    depth: 100,
					    modifier: 1,
					    slideShadows : true
				    }
				});
				//mySwiper
  		}
  	})
  }
  
  //会员精选/超值精选 跳转  （区分礼品券、优惠券详情页面不同）
  $scope.gogiftdel = function(type,id){
  	if(type == 1){
  		$state.go('tab.vip',{id:id})
  	}
  	if(type == 2){
  		$state.go('tab.czjx',{id:id})
  	}
  }
  $scope.go_vipCoupon_del = function(type,id){
  	if(type == 1){//代金券
  		$state.go('tab.vip_coupon_d',{id:id});
  	}
  	if(type == 2){//礼品券
  		$state.go('tab.vip_good_d',{id:id});
  	}
  }

//会员福利/会员专享；
  $scope.get_push_coupon = function(){
		var params = {page:1,rows:2,couponType:1};
		mineModule.http('getGoodList',params).then(function(data){
      // console.log("获取到的推送代金券："+JSON.stringify(data));
      if(data.length>=2){//代金券显示，新店推荐就显示3条；
        $scope.vip1 = data[0];
        $scope.vip2 = data[1];
        $scope.vip_hide = false;
        homeModule.shops_list().then(function(res){
          $scope.statu_count++;
          // console.log("新店推荐："+JSON.stringify(res));
          if( res.shopList.length >= 3){
            $scope.shops_items = res.shopList.slice(0,3) ;
          }else{
            $scope.shops_items = res.shopList ;
          }
          $scope.shops_IP = res.imageIp;
        })

      }else{//代金券没有两条就不显示 推荐店铺就显示六条
        $scope.vip_hide = true;
        homeModule.shops_list().then(function(res){
          $scope.shops_items = res.shopList ;
          $scope.shops_IP = res.imageIp;
        })

      }
		})
  }
//超值精选；
  $scope.get_push_goods = function(){
		var param = {page:1,rows:50,couponType:2};
		mineModule.http('getGoodList',param).then(function(data){
      // console.log("获取到的推送礼品券："+JSON.stringify(data));
      if(data.length>0){
        $scope.statu_count++;
        $scope.goods = data;
        $scope.list_notice = "精选的都在这了~"
      }else{
         $scope.list_notice = "暂无相关精选！"
      }
      
		})
  }
 
  //初始化活动列表（不要登录但是要做刷新）
  $scope.init_active = function(){
    homeModule.active_list().then(function(res){
      console.log("获取的图片："+ JSON.stringify(res))
      $scope.items = res.actList;
      $scope.IP = res.imageIp;
      $ionicSlideBoxDelegate.update(); //解决图片加载不出来的问题
      if(res.actList.length > 2 ){
        $ionicSlideBoxDelegate.$getByHandle("slideboximgs").loop(true);
      }else{
        $ionicSlideBoxDelegate.$getByHandle("slideboximgs").loop(false);
      }
    })
  }

  // 页面初始化数据///////////////////////////////////////////////////////////////////////////////////
  if(Storage.ls_get("user_infos")){//在本地存有会员信息 已经登录过
    //初始化登录后的所有数据；
    $scope.get_member_coupon();//获取会员相关信息（必须登录后，才能取金龙那边接口）
    $scope.get_park_info();//获取停车信息；（必须登录后查看）
    $scope.get_mine_coupon();//获取会员已领优惠券（必须登录、滑动展示）
    $scope.init_active();//初始化活动列表；
    $scope.get_push_goods(); //获取礼品券；
    $scope.get_push_coupon();// 获取代金券；
  }else{//本地没存有会员相关信息。未登录状态；
    // 初始化未登录的状态，会员能看到的信息；
    $scope.init_active();//初始化活动列表；
    //新店入场；
    $scope.get_push_goods(); //获取礼品券；
    $scope.get_push_coupon();// 获取代金券；

  }
  //页面数据下拉刷新
  $scope.doRefresh = function() {
    // 页面初始化数据///////////////////////////////////////////////////////////////////////////////////
    if(Storage.ls_get("user_infos")){//在本地存有会员信息 已经登录过
      //初始化登录后的所有数据；
      $scope.get_member_coupon();//获取会员相关信息（必须登录后，才能取金龙那边接口）
      $scope.get_park_info();//获取停车信息；（必须登录后查看）
      $scope.get_mine_coupon();//获取会员已领优惠券（必须登录、滑动展示）
      $scope.init_active();//初始化活动列表；
      $scope.get_push_goods(); //获取礼品券；
      $scope.get_push_coupon();// 获取代金券；

      //定时轮询问
      var Refresh_timer6 = window.setTimeout(function() {
          $scope.$broadcast('scroll.refreshComplete');
          window.clearTimeout(Refresh_timer6);
      }, 5000);
    }else{//本地没存有会员相关信息。未登录状态；
      // 初始化未登录的状态，会员能看到的信息；
      $scope.init_active();//初始化活动列表；
      //新店入场；
      $scope.get_push_goods(); //获取礼品券；
      $scope.get_push_coupon();// 获取代金券；
      //定时轮询问
      var Refresh_timer3 = window.setTimeout(function() {
          $scope.$broadcast('scroll.refreshComplete');
          window.clearTimeout(Refresh_timer3);
      }, 5000);
    }
    
  };
  
  //测试登录信息验证：
  $scope.is_phone = true;
  $scope.is_num = true;
  //登录按钮活跃状态
  $scope.isact = true;
//页面生命周期监听函数；
  $scope.$on('$ionicView.beforeEnter', function() { //监听本地会员信息是否被删除了；
    // 在里面获取存储的用户信息逻辑
    var S_info = Storage.ls_get("user_infos");
    if( Storage.ls_get("user_infos") ){//获取到之前的信息
      $scope.get_member_coupon();//会员的等级 ， 积分 ，电话等相关信息；
      $scope.get_mine_coupon();//显示会员已购买的优惠；
      $scope.get_park_info();//停车场信息；
      $scope.member_info =JSON.parse(Storage.ls_get("user_infos")) ;
      //头像显示
	    if($scope.member_info.m_sex == 1){//男士
	    	$scope.imgSrc = "img/icons/man.png"
	    }else if($scope.member_info.m_sex == 2){//女士
	    	$scope.imgSrc = "img/icons/wman.png"
	    }else{//保密或者未录入信息
	    	$scope.imgSrc = "img/icons/tx.png"
	    }
      $scope.no_user_infos = false;//显示会员信息区域
      $scope.no_login = false// 登录入口隐藏
    }else{//未获取到当前信息（表示未登录，需要重新登录）
      $scope.no_login = true;//显示登录按钮
      //隐藏信息显示区域
      $scope.no_user_infos = true;
      $scope.member_info = {} ;
       
    }
    // console.log("本地获取用户信息："+Storage.ls_get("user_infos"));
     // 初始化显示记住的密码
    if(Storage.ls_get("user&pwd")){
      $scope.n_user_info = JSON.parse(Storage.ls_get("user&pwd"));
    }else{
      $scope.member_info={};
    }
  });  



//更多商铺列表跳转；
  $scope.get_more = function(){
    $state.go('tab.moreList');
  }
//登录页面
  $ionicModal.fromTemplateUrl('templates/modal.html', {
      scope: $scope
  }).then(function(modal) {
      $scope.modal = modal;
  });
//new 登录注册模块
// 10200 //请求成功!  10201 // 验证码失效  10202 // 该手机尚未注册!  10203 // 手机号已经被注册  10204 //手机号或者密码错误!
    //登录方式切换
    //默认初始化显示快登陆
    $scope.pwd_login_2 = false;
    $scope.test_code_login_2 = true;
    $scope.show_M = 0;
    $scope.changeModel = function(n){
      $scope.show_M = n;
      if( n == 0){
         $scope.pwd_login_2 = false;
         $scope.test_code_login_2 = true;
      }else{
         $scope.pwd_login_2 = true;
         $scope.test_code_login_2 = false;
      }
    }
    //登录注册切换
    $scope.display_login = true;
    $scope.display_register = false;
    $scope.m_title = "登录"
    $scope.change_page = function(num){
      if(num == 0){
        $scope.display_login = true;
        $scope.display_register = false;
        $scope.m_title = "登录"
      }
      if(num == 1){
        $scope.display_login = false;
        $scope.display_register = true;
        $scope.m_title = "注册"
      }
      $scope.captcha = {
        paracont: '获取验证码',
        is_disable: false,
        paraevent: true
      };
    }

    //登录逻辑(快捷登录)
    //获取验证码
    $scope.user_info = {};
    $scope.captcha = {
      paracont: '获取验证码',
      is_disable: false,
      paraevent: true
    };
    $scope.get_test_code = function(e){
      var mobile =  $scope.user_info.user_num;
      var area = document.getElementById('home_DL_area').value;
    	// alert(area);
      if ($scope.captcha.paraevent) {
        if (Common.checkMobile(mobile)) {
          $ionicLoading.show({
            template: '获取验证码...'
          });
          //调取验证码服务；
          Common.countDown($scope.captcha);
          loginModule.get_captcha(mobile,area).then(function(res){
            $ionicLoading.hide();
            if(res.result == 10202){
              $scope.change_page(1)//切换到登录页面
              $cordovaToast.show('该手机尚未注册,注册后可快捷登录!', 'long', 'center');
            }
          })
          var timer_DX = window.setTimeout(function(){
            $ionicLoading.hide();
            window.clearTimeout(timer_DX);
          },20000)
        }else{
          //手机号码不对；
        }
      } else {
          e.preventDefault();
      }
    }
    // 快捷登录(登录按钮)
    $scope.LOGIN = function(){
      var mobile =  $scope.user_info.user_num;
      var code = $scope.user_info.test_code;
      //正则及相关验证；
      var _rep = /\d{6}/.test(code);
      var _mobile = /^\d{5,}$/.test(mobile);
      if(mobile&&_mobile){//验证通过；
        $scope.phone_tc = " "
        if((_rep && code.length === 6)){//tongguo 
          $ionicLoading.show({
            template: '正在登录中...'
          });
          $scope.test_code_tc = " "
          loginModule.login(mobile,code).then(function(res){
            $ionicLoading.hide();
            // console.log("快捷登录的结果："+JSON.stringify(res))
            switch(res.result){//10200 //请求成功!10201 // 验证码失效10202 // 该手机尚未注册!10203 // 手机号已经被注册10204 //手机号或者密码错误!
              case 10200:
                // alert("请求成功");
                //掉用成功的方法
                $scope.member_info = res.member //绑定会员相关数据
                if($scope.member_info.m_sex == 1){//男士
                	$scope.imgSrc = "img/icons/man.png"
                }else if($scope.member_info.m_sex == 2){//女士
                	$scope.imgSrc = "img/icons/wman.png"
                }else{//保密或者未录入信息
                	$scope.imgSrc = "img/icons/tx.png"
                }
                // console.log("会员相关信息："+ $scope.member_info);
                //$scope.top_info = true; //切换已登录的模板
                $scope.no_user_infos = false;
                // $scope.no_user_infos = false;//显示会员信息区域
                Storage.ls_set("user_infos",$scope.member_info);//将会员信息本地存储
                //获取个人优惠券（轮播展示）
      					$scope.get_mine_coupon();
                $scope.modal.hide();//将会员信息本地存储
                $scope.get_member_coupon();//获取会员卡的等级
                $scope.get_park_info();//获取停车信息；（必须登录后查看）
                //隐藏登录入口
                $scope.no_login = false;
                //清除相关用户信息
                $scope.user_info.user_num = "";
                $scope.user_info.test_code = "";

                //记住密码（防止验证码登录后修改密码报错）
                $scope.id_pwd = {
                  user_num:mobile,
                  user_pwd:''
                };
                Storage.ls_set("user&pwd",$scope.id_pwd);//记住账号及密码

                $cordovaToast.show('登录成功!', 'long', 'center');
                break;
              case 10201:
                $cordovaToast.show('验证码失效或错误!', 'long', 'center');
                break;
              case 10202:
                $cordovaToast.show('该手机尚未注册', 'long', 'center');
                break;
              case 10203:
                $cordovaToast.show('手机号已经被注册', 'long', 'center');
                break;
              case 10204:
                $cordovaToast.show('手机号或者密码错误', 'long', 'center');
                break;
              default:
                $cordovaToast.show('出错了，稍后再试', 'long', 'center');
            }
          })

          var timer_DXDL = window.setTimeout(function(){
            $ionicLoading.hide();
            window.clearTimeout(timer_DXDL);
          },20000)

        }else{//手机号错误
          $scope.test_code_tc = "请输入6位正确的验证码"
        }
      }else{//验证码未填或填错；
        $scope.phone_tc = "请输入正确的手机号码"
      }
    }
    //清除验证状态
    $scope.phone_test = function(){//手机号码状态清除
      $scope.phone_tc = " ";
      //账号密码登录状态
      $scope.reg_notice_phone = "";//手机号正则状态清除
      $scope.pwd_login_res = "";//登陆结果状态
    }
    $scope.verification_test = function(){//验证码状态清除
      $scope.test_code_tc = " ";
      //账号密码登录状态
      $scope.reg_notice_pwd = "";//pwd正则状态清除
      $scope.pwd_login_res = "";//登陆结果状态
    }

//账号密码登录
    $scope.n_user_info = {};
    $scope.login_pwd = function(){
      var p_user = $scope.n_user_info.user_num;
      var P_pwd = $scope.n_user_info.user_pwd;
      //正则验证；
      // var reg_pwd = /^[a-zA-Z]\w{5,17}$/;
      var reg_mobile = /^\d{5,}$/;
      if(reg_mobile.test(p_user)){//手机号验证通过
        if(P_pwd&&P_pwd.length>7){//密码正则通过
          $ionicLoading.show({
            template: '正在登录中...'
          });
          var md5_pwd = md5.createHash(P_pwd);
          // console.log(md5_pwd);
          //进行登录
          loginModule.n_login(p_user,md5_pwd).then(function(res){
            $ionicLoading.hide();
            // console.log("会员细信息："+JSON.stringify(res));
            switch(res.result){//10200 //请求成功!10201 // 验证码失效10202 // 该手机尚未注册!10203 // 手机号已经被注册10204 //手机号或者密码错误!
              case 10200:
                // alert("请求成功");
                //显示会员相关信息
                $scope.member_info = res.member;
                if($scope.member_info.m_sex == 1){//男士
                	$scope.imgSrc = "img/icons/man.png"
                }else if($scope.member_info.m_sex == 2){//女士
                	$scope.imgSrc = "img/icons/wman.png"
                }else{//保密或者未录入信息
                	$scope.imgSrc = "img/icons/tx.png"
                }
                Storage.ls_set("user_infos",res.member);
                
                $scope.no_user_infos = false;//显示个人信息这块
                $scope.no_login = false//关闭登录入口
                $scope.modal.hide();//隐藏登录
      					$scope.get_mine_coupon();//获取个人优惠券（轮播展示）
                $scope.get_member_coupon();//获取会员等级
                $scope.get_park_info();//获取停车信息；（必须登录后查看）
                // 记住密码；
                if($scope.ischecked){
                  Storage.ls_set("user&pwd", $scope.n_user_info);//记住账号及密码
                }else{
                  Storage.ls_delete("user&pwd");//账号
                  $scope.n_user_info = {};//删除账号及密码
                }
                $cordovaToast.show('登录成功!', 'long', 'center');
                break;
              case 10201:
                $scope.pwd_login_res = "验证码失效或错误"
                break;
              case 10202:
                $scope.pwd_login_res = "该手机尚未注册"
                break;
              case 10203:
                $scope.pwd_login_res = "手机号已经被注册"
                break;
              case 10204:
                $scope.pwd_login_res = " 手机号或者密码错误"
                break;
              default:
                $scope.pwd_login_res = "出错了，稍后再试"
            }
           
          })
          
          var timer_MMDL = window.setTimeout(function(){
            $ionicLoading.hide();
            window.clearTimeout(timer_MMDL);
          },20000)

        }else{//密码正则未通过
           $scope.reg_notice_pwd = "数字和者字母（6到18位）"
        }
      }else{//手机号正则不通过
        $scope.reg_notice_phone = "手机号不正确"
      }
    }
  //获取或设置复选框是否选中
  $scope.ischecked = false;
  //点击切换显密码
  $scope.show_pwd_value = "显示"
  $scope.show_pwd = function(){
    var input = document.getElementById("pwd");
    if(input.type == "text"){
      // console.log("pwd")
      input.type = "password";
      $scope.show_pwd_value = "显示"
    }else{
      // console.log("text")
      input.type = "text";
      $scope.show_pwd_value = "隐藏"
    }
  }

   //注册模块
  $scope.register_info = {};//存放用户注册信息
  $scope.register = function(){
    //正则验证
    var r_mobile = $scope.register_info.phone
    var r_pwd = $scope.register_info.pwd;
    var r_code = $scope.register_info.code;
    var _mobile = /^\d{5,}$/.test(r_mobile);
    var _code = /\d{6}/.test(r_code);
    var area = document.getElementById('home_ZC_area').value;
    // alert(area);
    if(_mobile){
      if(r_pwd && r_pwd.length>7 ){
        if(_code){
          $ionicLoading.show({
            template: '正在注册中...'
          });
          var params = {
            m_phone : r_mobile,
            code : r_code ,
            m_pass : md5.createHash( r_pwd ),
            area:area
          };
          loginModule.register(params).then(function(res){
            // console.log("注册结果"+JSON.stringify(res));
            $ionicLoading.hide();
            switch(res.result){
              case 10200:
                $scope.change_page(0);//切换至登录模块
                $cordovaToast.show('注册成功,马上登录!', 'long', 'center');
                break;
              case 10201:
                $scope.r_pwd_login_res_code = "验证码失效或错误";
                break;
              case 10202:
                $scope.r_pwd_login_res = "该手机尚未注册";
                break;
              case 10203:
                $scope.r_pwd_login_res = "手机号已经被注册";
                break;
              case 10204:
                $scope.r_pwd_login_res = " 手机号或者密码错误";
                break;
              default:
                $scope.r_pwd_login_res = "出错了，稍后再试";
            }
          })

          var timer_ZC = window.setTimeout(function(){
            $ionicLoading.hide();
            window.clearTimeout(timer_ZC);
          },20000)

        }else{
          $ionicPopup.alert({
            title: '提示',
            template: '请输入6位数字密码！'
          });
        }
      }else{
        $scope.r_pwd_num = "密码为8位以上数字或字母"
      }
    }else{
      $scope.r_phone_num = "手机号码不正确"
    }
   
  }
  //清除注册提示状态
  $scope.hide_notice = function(){
    $scope.r_phone_num = "";
    $scope.r_pwd_num = "";
    $scope.r_pwd_login_res_code = "";
    $scope.r_pwd_login_res = "";
  }
  // 验证码(注册模块)
  $scope.register_code = function(e){
    var phone =  $scope.register_info.phone;
    var area = document.getElementById('home_ZC_area').value;
    // alert(area);
    // alert(phone);
    if ($scope.captcha.paraevent) {
      if (Common.checkMobile(phone)){
        $ionicLoading.show({
          template: '获取验证码...'
        });
        //调取验证码服务；
        loginModule.reg_captcha(phone,area).then(function(res){
          $ionicLoading.hide();
          // console.log(res);
          if(res.result == "10203"){
            $scope.r_pwd_login_res = "手机号已经注册，请直接登录";
          }else{
            Common.countDown($scope.captcha);
          }
        })

        
        var timer_ZCDX = window.setTimeout(function(){
          $ionicLoading.hide();
          window.clearTimeout(timer_ZCDX);
        },20000)

      }else{
        //手机号码不对；
      }
    } else {
        e.preventDefault();
    }
  }
  //重置验证码提示消息
  $scope.set_code_notice = function(){
     $scope.r_pwd_login_res = " "
  }
  //切换密码
  $scope.ischecked = true;//初始化为记住密码状态
  $scope.toggle_pwd = function(){
    if($scope.ischecked){
      $scope.ischecked = false;
    }else{
      $scope.ischecked = true;
    }
  }

})

//d店铺详情
.controller('shop_detailCtrl', function($cordovaToast,Storage,$scope,$state,$stateParams,$ionicHistory,homeModule,mineModule){
  // 返回按钮功能
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  //$stateParams 接收传递过来的参数；// console.log("最新店铺列表传过来的id："+JSON.stringify($stateParams));
  $scope.shop_id = $stateParams.shop_id;
  // 查询店铺详情 getShopDetail int shop_id
  homeModule.shop_detail("getShopDetail", $scope.shop_id ).then(function(res){
    $scope.data = res.shop;
    //  console.log("详情内容1："+JSON.stringify($scope.data));
    $scope.imageIp=res.imageIp;
    //  console.log("详情内容2："+JSON.stringify($scope.imageIp));
  })

  //初始化进来判断店铺有没有被收藏（根据状态显示对应图标）判断收藏状态 isBook 参数 sb_s_id,sb_m_id返回 true (已经收藏)False
      //先判断用户是否登录过，未登录显示未收藏，如果点击收藏的话提示登录后才可以收藏；
  $scope.iscare = function(){
    var params = {
      sb_s_id:$scope.shop_id,
      sb_m_id:m_id
    }
    // console.log("params:"+JSON.stringify(params))
    mineModule.http("isBook",params).then(function(res){
      // console.log("isbook:"+JSON.stringify(res));
      if(res){//已经收藏
        $scope.un_care = false;
      }else{//未收藏
        $scope.un_care = true
      }
    })
  }

//初始化显示图标
  if(Storage.ls_get("user_infos")){//已登录
    var m_id =JSON.parse(Storage.ls_get("user_infos")).m_id;
    $scope.iscare();
  }else{//未登录
    $scope.un_care = true//显示未收藏的图标；
  }
  //收藏/收藏店铺 addShopBook 参数 sb_s_id,sb_m_id  /取消收藏 deleteShopBook 参数 sb_s_id,sb_m_id
  $scope.toggle_care = function(n){
    //先要判断是否登录，已登录
    if(Storage.ls_get("user_infos")){
      var params = {//传递参数
        sb_s_id:$scope.shop_id,//店铺ID
        sb_m_id:m_id//会员ID
      }
      switch(n){
        case 0://收藏
          // console.log("收藏params:"+JSON.stringify(params))
          mineModule.http("addShopBook",params).then(function(res){
            // console.log("操作结果："+JSON.stringify(res))
            if(res.success){
              // alert("操作成功！")
              $scope.iscare();//重新初始化图标状态
              $cordovaToast.show('收藏成功！', 'long', 'center');
            }else{
              // alert("操作失败，稍后再试")
              $cordovaToast.show('操作失败，稍后再试！', 'long', 'center');
            }
          })
          break;
        case 1://取消收藏
          // console.log("取消收藏params:"+JSON.stringify(params))
          mineModule.http("deleteShopBook",params).then(function(res){
            // console.log("操作结果："+JSON.stringify(res))
            if(res.success){
              $scope.iscare();//重新初始化图标状态
              $cordovaToast.show('取消收藏成功！', 'long', 'center');
            }else{
              $cordovaToast.show('操作失败，稍后再试！', 'long', 'center');
            }
          })
          break;
      }
    }else{//未登录（提示登录后才能收藏）
      // alert("登录后才能收藏")
      $cordovaToast.show('登录后才能收藏！', 'long', 'center');
    }
    
   

  }
})
//店铺详情


// 获取更多店铺列表；
.controller('moreListCtrl', function(findModule,$ionicHistory,$scope,Common,$state,mineModule,$translate,homeModule,$ionicSlideBoxDelegate) {
  //返回按钮事件；
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  //获取楼层
  // getFloorSteps
  $scope.getfloor = function(){
      findModule.get_floor("getFloorSteps").then(function(res){
          $scope.floors = res;
          $scope.i = $scope.floors[0].floor_id;//默认第一个楼层显示为活动状态；
          // console.log("楼层信息："+JSON.stringify(res)); //初始化获取默认在活动楼层的店铺列表；
          $scope.params = {shop_floor:$scope.i};
          findModule.get_brand_list("getShopAndFloorByShop_floor",$scope.params).then(function(res){
              
              $scope.floor = res.floorMap;
              $scope.shop_lists = res.shopList;
              for( var i = 0;i<$scope.shop_lists.length;i++){
                  if($scope.shop_lists[i].shop_home == "1"){
                      $scope.shop_lists[i].isRecommend = true;//显示推荐图标
                  }else{
                        $scope.shop_lists[i].isRecommend = false;//隐藏推荐图标；
                  }
              }
              // console.log("初始化显示第一楼的列表"+JSON.stringify($scope.shop_lists));
              $scope.IMG = res.imageIp;
          })
      })
  }
  $scope.getfloor();//初始化楼层
  //切换：按楼层/按品牌；// 初始化默认先显示按楼层
  $scope.is_floor = true;
  $scope.is_select = false;
  //切换显示：品类/楼层
  $scope.show_type = "按品类"
  $scope.show = function(){
      if($scope.show_type == "按品类"){
          $scope.show_type = "按楼层"
          $scope.is_floor = false;
          $scope.is_select = true;
          $scope.get_category();//获取品类列表
      }else{
          $scope.show_type = "按品类"
          $scope.is_floor = true;
          $scope.is_select = false;
          $scope.getfloor();//切换显示楼层相关数据
      }
      
  }
  //点击当前楼层显示活跃状态；并获取当前楼层的所有店铺；
  $scope.is_active = function(n){
      // n 为店铺的id
      $scope.i=n;
      // console.log("=================="+$scope.i);// 根据楼层获取商铺列表// getShopByShop_floor   getShopAndFloorByShop_floor// String shop_floor
      $scope.params = {shop_floor:$scope.i};
      findModule.get_brand_list("getShopAndFloorByShop_floor",$scope.params).then(function(res){
          // console.log("111111111111111111111111"+JSON.stringify(res));
          $scope.floor = res.floorMap;
          $scope.shop_lists = res.shopList;
          for( var i = 0;i<$scope.shop_lists.length;i++){
              if($scope.shop_lists[i].shop_home == "1"){
                  $scope.shop_lists[i].isRecommend = true;
              }else{
                  $scope.shop_lists[i].isRecommend = false;
              }
          }
          $scope.IMG = res.imageIp;
      })
  }

  //获取品类数据；获取商铺类别列表getShop_type 返回 zdxId,zdxName
  $scope.get_category = function(){
    var params = {};
    mineModule.http("getShop_type",params).then(function(res){
      // console.log("获取的店铺品类："+JSON.stringify(res));
      $scope.shop_type = res;
      var selected = res[0].zdxId
      $scope.get_shop_list(selected);
    })
  }

  //按品类搜索店铺；根据类别获取商铺 getShopByShop_type 参数 shop_type 就是 zdxId
  $scope.get_shop_list = function(selected){
    // console.log("选中的分类为："+selected)
    var params = {
      shop_type:selected
    }
    mineModule.http("getShopByShop_type",params).then(function(res){
      // console.log("获取分类列表："+JSON.stringify(res));
      $scope.floor.floor_title = res.type_name;
      $scope.floor.floor_num = ""//清除楼层显示
      $scope.shop_lists = res.shopList;
      for( var i = 0;i<$scope.shop_lists.length;i++){
          if($scope.shop_lists[i].shop_home == "1"){
              $scope.shop_lists[i].isRecommend = true;//显示推荐图标
          }else{
                $scope.shop_lists[i].isRecommend = false;//隐藏推荐图标；
          }
      }
      $scope.IMG = res.imageIp;
    })
  }
})

//QR
.controller('QRCtrl', function($scope,$state,$stateParams,$ionicHistory,mineModule){
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  $scope.str = $stateParams.id
//	alert($scope.str);
  //获取二维码链接 getQRcode couponcode
  $scope.get_QR = function(){
  	var params = {
  		cardNo:$scope.str
  	};
  	mineModule.http("getMemberQRcode",params).then(function(res){
	  	console.log("IMG:"+JSON.stringify(res));
      $scope.imgSrc = res.resulturl;
      $scope.cardNum = res.key
  	})
  }
	$scope.get_QR();
})
//QR

//超值精选详情
.controller('h_goodsCtrl',function($ionicPopup,$state,Storage,Common,md5,$ionicLoading,$ionicModal,loginModule,$scope,$ionicTabsDelegate,$ionicHistory,$stateParams,mineModule){
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  //登录页面
  $ionicModal.fromTemplateUrl('templates/modal.html', {
      scope: $scope
  }).then(function(modal) {
      $scope.modal = modal;
  });
  //登录页面
  //获取传递过来的id
  $scope.good_id = $stateParams.id;
  // console.log("礼品："+ $scope.good_id );

  //通过ID获取商品详情
  $scope.get_good_details = function(){
     var params = {
      goodsId:$scope.good_id
    }
    mineModule.http("getGoodDetail",params).then(function(res){
      // console.log("good:"+JSON.stringify(res));
      if(res.code = 10000){
        $scope.good_details = res.info;
        //格式化要显示的数据
        $scope.good_details.levels = $scope.good_details.levels.join(" ");
        if($scope.good_details.couponInfo.beginTime){
          $scope.good_details.couponInfo.beginTime = $scope.good_details.couponInfo.beginTime.split(" ")[0];
        }
        if( $scope.good_details.couponInfo.endTime){
          $scope.good_details.couponInfo.endTime = $scope.good_details.couponInfo.endTime.split(" ")[0];
        }
        // console.log("good详情："+JSON.stringify($scope.good_details));
      }else{
        alert("获取数据出错了！")
      }

    })
  }
  $scope.get_good_details();
  //判断是否登录
  $scope.go_confirm = function(){
    if(Storage.ls_get("user_infos")){
      //登录过直接跳转确认订单页面
      $state.go("tab.h_confirm_order",{id:$scope.good_id});
    }else{
      $scope.modal.show();
    }
  }

  
//new 登录注册模块
// 10200 //请求成功!  10201 // 验证码失效  10202 // 该手机尚未注册!  10203 // 手机号已经被注册  10204 //手机号或者密码错误!
    //登录方式切换
      //默认初始化显示快登陆
      $scope.pwd_login_2 = false;
      $scope.test_code_login_2 = true;
      $scope.show_M = 0;
    $scope.changeModel = function(n){
      $scope.show_M = n;
      if( n == 0){
         $scope.pwd_login_2 = false;
         $scope.test_code_login_2 = true;
      }else{
         $scope.pwd_login_2 = true;
         $scope.test_code_login_2 = false;
      }
    }
    //登录注册切换
    $scope.display_login = true;
    $scope.display_register = false;
    $scope.m_title = "登录"
    $scope.change_page = function(num){
      if(num == 0){
        $scope.display_login = true;
        $scope.display_register = false;
        $scope.m_title = "登录"
      }
      if(num == 1){
        $scope.display_login = false;
        $scope.display_register = true;
        $scope.m_title = "注册"
      }
      $scope.captcha = {
        paracont: '获取验证码',
        is_disable: false,
        paraevent: true
      };
    }

    //登录逻辑(快捷登录)
    //获取验证码
    $scope.user_info = {};
    $scope.captcha = {
      paracont: '获取验证码',
      is_disable: false,
      paraevent: true
    };
    $scope.get_test_code = function(e){
      var mobile =  $scope.user_info.user_num;
      var area = document.getElementById('good_DL_area').value;
    // alert(area);
      if ($scope.captcha.paraevent) {
        if (Common.checkMobile(mobile)) {
          // console.log(mobile);
          $ionicLoading.show({
            template: '获取验证码...'
          });
          //调取验证码服务；
          Common.countDown($scope.captcha);
          loginModule.get_captcha(mobile,area).then(function(res){
            $ionicLoading.hide();
            if(res.result == 10202){
              $scope.change_page(1)//切换到登录页面
              $cordovaToast.show('该手机尚未注册,注册后可快捷登录!', 'long', 'center');
              // alert("该手机尚未注册,注册后可快捷登录!");
            }
          })
        }else{
          //手机号码不对；
        }
      } else {
          e.preventDefault();
      }
    }
    // 快捷登录(登录按钮)
    $scope.LOGIN = function(){
      // console.log("开始验证了+++++++++++++++++++++++++++++++++++++")
      var mobile =  $scope.user_info.user_num;
      var code = $scope.user_info.test_code;
      //正则及相关验证；
      var _rep = /\d{6}/.test(code);
      var _mobile = /^\d{5,}$/.test(mobile);
      if(mobile&&_mobile){//验证通过；
        $scope.phone_tc = " "
        if((_rep && code.length === 6)){//tongguo 
          $ionicLoading.show({
            template: '正在登录中...'
          });
          $scope.test_code_tc = " "
          loginModule.login(mobile,code).then(function(res){
            $ionicLoading.hide();
            // console.log("快捷登录的结果："+JSON.stringify(res))
            switch(res.result){//10200 //请求成功!10201 // 验证码失效10202 // 该手机尚未注册!10203 // 手机号已经被注册10204 //手机号或者密码错误!
              case 10200:
                // alert("请求成功");
                //掉用成功的方法
                $scope.member_info = res.member //绑定会员相关数据
                // console.log("会员相关信息："+ $scope.member_info);
                //$scope.top_info = true; //切换已登录的模板
                $scope.no_user_infos = false;
                // $scope.no_user_infos = false;//显示会员信息区域
                Storage.ls_set("user_infos",$scope.member_info);//将会员信息本地存储
                $scope.modal.hide();//将会员信息本地存储
                //$state.go("tab.confirm_order",{id:$scope.coupon_id});//跳转对应的优惠券详情页面//////////////////////////
                //隐藏登录入口
                $scope.no_login = false;
                //清除相关用户信息
                $scope.user_info.user_num = "";
                $scope.user_info.test_code = "";

                //记住密码（防止验证码登录后修改密码报错）
                $scope.id_pwd = {
                  user_num:mobile,
                  user_pwd:''
                };
                Storage.ls_set("user&pwd",$scope.id_pwd);//记住账号及密码

                $cordovaToast.show('登录成功!', 'long', 'center');
                break;
              case 10201:
                // alert("");
                $cordovaToast.show('验证码失效或错误!', 'long', 'center');
                break;
              case 10202:
                // alert("");
                $cordovaToast.show('该手机尚未注册', 'long', 'center');
                break;
              case 10203:
                // alert("");
                $cordovaToast.show('手机号已经被注册', 'long', 'center');
                break;
              case 10204:
                // alert("");
                $cordovaToast.show('手机号或者密码错误', 'long', 'center');
                break;
              default:
                // alert("");
                $cordovaToast.show('出错了，稍后再试', 'long', 'center');
            }
          })
        }else{//手机号错误
          $scope.test_code_tc = "请输入6位正确的验证码"
        }
      }else{//验证码未填或填错；
        $scope.phone_tc = "请输入正确的手机号码"
      }
    }
    //清除验证状态
    $scope.phone_test = function(){//手机号码状态清除
      $scope.phone_tc = " ";
      //账号密码登录状态
      $scope.reg_notice_phone = "";//手机号正则状态清除
      $scope.pwd_login_res = "";//登陆结果状态
    }
    $scope.verification_test = function(){//验证码状态清除
      $scope.test_code_tc = " ";
      //账号密码登录状态
      $scope.reg_notice_pwd = "";//pwd正则状态清除
      $scope.pwd_login_res = "";//登陆结果状态
    }

//账号密码登录
    $scope.n_user_info = {};
    $scope.login_pwd = function(){
      
      var p_user = $scope.n_user_info.user_num;
      var P_pwd = $scope.n_user_info.user_pwd;
      //正则验证；
      // var reg_pwd = /^[a-zA-Z]\w{5,17}$/;
      var reg_mobile = /^\d{5,}$/;

      if(reg_mobile.test(p_user)){//手机号验证通过
        if(P_pwd&&P_pwd.length>7){//密码正则通过
          $ionicLoading.show({
            template: '正在登录中...'
          });
          var md5_pwd = md5.createHash(P_pwd);
          // console.log(md5_pwd);
          //进行登录
          loginModule.n_login(p_user,md5_pwd).then(function(res){
            $ionicLoading.hide();
            // console.log("会员细信息："+JSON.stringify(res));
            switch(res.result){//10200 //请求成功!10201 // 验证码失效10202 // 该手机尚未注册!10203 // 手机号已经被注册10204 //手机号或者密码错误!
              case 10200:
                // alert("请求成功");
                //显示会员相关信息
                $scope.member_info = res.member;
                Storage.ls_set("user_infos",res.member);
                $scope.no_user_infos = false;//显示个人信息这块
                $scope.no_login = false//关闭登录入口
                //隐藏登录
                $scope.modal.hide();
                //$state.go("tab.confirm_order",{id:$scope.coupon_id});//跳转对应的优惠券详情页面//////////////////////////
                // 记住密码；
                if($scope.ischecked){
                  // alert("记住密码")
                  Storage.ls_set("user&pwd", $scope.n_user_info);//记住账号及密码
                }else{
                  Storage.ls_delete("user&pwd");//账号
                  // alert("删除密码")
                  $scope.n_user_info = {};//删除账号及密码
                }
                $cordovaToast.show('登录成功!', 'long', 'center');
                break;
              case 10201:
                // alert("验证码失效");
                $scope.pwd_login_res = "验证码失效或错误"
                break;
              case 10202:
                // alert("该手机尚未注册");
                $scope.pwd_login_res = "该手机尚未注册"
                break;
              case 10203:
                // alert("手机号已经被注册");
                $scope.pwd_login_res = "手机号已经被注册"
                break;
              case 10204:
                // alert("手机号或者密码错误");
                $scope.pwd_login_res = " 手机号或者密码错误"
                break;
              default:
                // alert("出错了，稍后再试");
                $scope.pwd_login_res = "出错了，稍后再试"
            }
           
          })
        }else{//密码正则未通过
           $scope.reg_notice_pwd = "数字和者字母（6到18位）"
        }
      }else{//手机号正则不通过
        $scope.reg_notice_phone = "手机号不正确"
      }

    }
  //获取或设置复选框是否选中
  $scope.ischecked = false;
  //点击切换显密码
  $scope.show_pwd_value = "显示"
  $scope.show_pwd = function(){
    var input = document.getElementById("pwd");
    if(input.type == "text"){
      // console.log("pwd")
      input.type = "password";
      $scope.show_pwd_value = "显示"
    }else{
      // console.log("text")
      input.type = "text";
      $scope.show_pwd_value = "隐藏"
    }

  }

   //注册模块
  $scope.register_info = {};//存放用户注册信息
  $scope.register = function(){
   
    //正则验证
    var r_mobile = $scope.register_info.phone
    var r_pwd = $scope.register_info.pwd;
    var r_code = $scope.register_info.code;
    var _mobile = /^\d{5,}$/.test(r_mobile);
    var area = document.getElementById('good_ZC_area').value;
    // alert(area);
    var _code = /\d{6}/.test(r_code);
    if(_mobile){
      if(r_pwd && r_pwd.length>7 ){
        if(_code){
          $ionicLoading.show({
            template: '正在注册中...'
          });
          var params = {
            m_phone : r_mobile,
            code : r_code ,
            m_pass : md5.createHash( r_pwd ),
            area:area
          };
          loginModule.register(params).then(function(res){
            // console.log("注册结果"+JSON.stringify(res));
            $ionicLoading.hide();
            switch(res.result){
              case 10200:
                // alert("注册成功,马上登录");
                $scope.change_page(0);//切换至登录模块
                $cordovaToast.show('注册成功,马上登录!', 'long', 'center');
                break;
              case 10201:
                $scope.r_pwd_login_res_code = "验证码失效或错误";
                break;
              case 10202:
                $scope.r_pwd_login_res = "该手机尚未注册";
                break;
              case 10203:
                $scope.r_pwd_login_res = "手机号已经被注册";
                break;
              case 10204:
                $scope.r_pwd_login_res = " 手机号或者密码错误";
                break;
              default:
                $scope.r_pwd_login_res = "出错了，稍后再试";
            }
          })
        }else{
          $ionicPopup.alert({
            title: '提示',
            template: '请输入6位数字验证码！'
          });
        }
      }else{
        // alert("密码为8位以上数字或字母")
        $scope.r_pwd_num = "密码为8位以上数字或字母"
      }
    }else{
      // alert("手机号码不正确")
      $scope.r_phone_num = "手机号码不正确"
    }
   
  }
  //清除注册提示状态
  $scope.hide_notice = function(){
    $scope.r_phone_num = "";
    $scope.r_pwd_num = "";
    $scope.r_pwd_login_res_code = "";
    $scope.r_pwd_login_res = "";
  }
  // 验证码(注册模块)
  $scope.register_code = function(e){
    var phone =  $scope.register_info.phone;
    var area = document.getElementById('good_ZC_area').value;
    // alert(area);
    // alert(phone);
    if ($scope.captcha.paraevent) {
      if (Common.checkMobile(phone)){
        $ionicLoading.show({
          template: '获取验证码...'
        });
        //调取验证码服务；
        loginModule.reg_captcha(phone,area).then(function(res){
          $ionicLoading.hide();
          // console.log(res);
          if(res.result == "10203"){
            $scope.r_pwd_login_res = "手机号已经注册，请直接登录";
          }else{
            Common.countDown($scope.captcha);
          }
        })
      }else{
        //手机号码不对；
      }
    } else {
        e.preventDefault();
    }
  }
  //重置验证码提示消息
  $scope.set_code_notice = function(){
     $scope.r_pwd_login_res = " "
  }
  //切换密码
  $scope.ischecked = true;//初始化为记住密码状态
  $scope.toggle_pwd = function(){
    if($scope.ischecked){
      $scope.ischecked = false;
    }else{
      $scope.ischecked = true;
    }
  }

})

//会员精选 h_couponCtrl
.controller('h_couponCtrl',function($ionicPopup,Common,md5,$ionicLoading,$ionicModal,loginModule,$scope,$state,Storage,$ionicTabsDelegate,$ionicHistory,$stateParams,mineModule){
  $scope.goback=function(){
    $ionicHistory.goBack();
  }

  //登录页面
  $ionicModal.fromTemplateUrl('templates/modal.html', {
      scope: $scope
  }).then(function(modal) {
      $scope.modal = modal;
  });
  //登录页面

  $scope.coupon_id = $stateParams.id;
  // console.log("优惠券："+ $scope.coupon_id );
  //获取优惠券信息详情；
  $scope.get_coupons_details = function(){
    var params = {
      goodsId:$scope.coupon_id
    }
    mineModule.http("getGoodDetail",params).then(function(res){
      // console.log("优惠券详情："+JSON.stringify(res))
      if( res.code == 10000 ){
        $scope.coupons_details = res.info;
        $scope.coupons_details.levels = $scope.coupons_details.levels.join(" ");
        if($scope.coupons_details.couponInfo.beginTime){
           $scope.coupons_details.couponInfo.beginTime = $scope.coupons_details.couponInfo.beginTime.split(" ")[0];
        }
        if($scope.coupons_details.couponInfo.endTime){
          $scope.coupons_details.couponInfo.endTime = $scope.coupons_details.couponInfo.endTime.split(" ")[0];
        }
      }else{
        alert("获取数据失败");
      }
    })
  }
  $scope.get_coupons_details();

  $scope.go_confirm = function(){
    if(Storage.ls_get("user_infos")){
      //登录过直接跳转确认订单页面
      $state.go("tab.h_confirm_order",{id:$scope.coupon_id});
    }else{
      $scope.modal.show();
    }
  }

//new 登录注册模块
// 10200 //请求成功!  10201 // 验证码失效  10202 // 该手机尚未注册!  10203 // 手机号已经被注册  10204 //手机号或者密码错误!
    //登录方式切换
      //默认初始化显示快登陆
      $scope.pwd_login_2 = false;
      $scope.test_code_login_2 = true;
      $scope.show_M = 0;
    $scope.changeModel = function(n){
      $scope.show_M = n;
      if( n == 0){
         $scope.pwd_login_2 = false;
         $scope.test_code_login_2 = true;
      }else{
         $scope.pwd_login_2 = true;
         $scope.test_code_login_2 = false;
      }
    }
    //登录注册切换
    $scope.display_login = true;
    $scope.display_register = false;
    $scope.m_title = "登录"
    $scope.change_page = function(num){
      if(num == 0){
        $scope.display_login = true;
        $scope.display_register = false;
        $scope.m_title = "登录"
      }
      if(num == 1){
        $scope.display_login = false;
        $scope.display_register = true;
        $scope.m_title = "注册"
      }
      $scope.captcha = {
        paracont: '获取验证码',
        is_disable: false,
        paraevent: true
      };
    }

    //登录逻辑(快捷登录)
    //获取验证码
    $scope.user_info = {};
    $scope.captcha = {
      paracont: '获取验证码',
      is_disable: false,
      paraevent: true
    };
    $scope.get_test_code = function(e){
      var mobile =  $scope.user_info.user_num;
      var area = document.getElementById('coupon_DL_area').value;
      // alert(area);
      if ($scope.captcha.paraevent) {
        if (Common.checkMobile(mobile)) {
          // console.log(mobile);
          $ionicLoading.show({
            template: '获取验证码...'
          });
          //调取验证码服务；
          Common.countDown($scope.captcha);
          loginModule.get_captcha(mobile,area).then(function(res){
            $ionicLoading.hide();
            if(res.result == 10202){
              $scope.change_page(1)//切换到登录页面
              $cordovaToast.show('该手机尚未注册,注册后可快捷登录!', 'long', 'center');
              // alert("该手机尚未注册,注册后可快捷登录!");
            }
          })
        }else{
          //手机号码不对；
        }
      } else {
          e.preventDefault();
      }
    }
    // 快捷登录(登录按钮)
    $scope.LOGIN = function(){
      // console.log("开始验证了+++++++++++++++++++++++++++++++++++++")
      var mobile =  $scope.user_info.user_num;
      var code = $scope.user_info.test_code;
      //正则及相关验证；
      var _rep = /\d{6}/.test(code);
      var _mobile = /^\d{5,}$/.test(mobile);
      if(mobile&&_mobile){//验证通过；
        $scope.phone_tc = " "
        if((_rep && code.length === 6)){//tongguo 
          $ionicLoading.show({
            template: '正在登录中...'
          });
          $scope.test_code_tc = " "
          loginModule.login(mobile,code).then(function(res){
            $ionicLoading.hide();
            // console.log("快捷登录的结果："+JSON.stringify(res))
            switch(res.result){//10200 //请求成功!10201 // 验证码失效10202 // 该手机尚未注册!10203 // 手机号已经被注册10204 //手机号或者密码错误!
              case 10200:
                // alert("请求成功");
                //掉用成功的方法
                $scope.member_info = res.member //绑定会员相关数据
                // console.log("会员相关信息："+ $scope.member_info);
                //$scope.top_info = true; //切换已登录的模板
                $scope.no_user_infos = false;
                // $scope.no_user_infos = false;//显示会员信息区域
                Storage.ls_set("user_infos",$scope.member_info);//将会员信息本地存储
                $scope.modal.hide();//将会员信息本地存储
                //$state.go("tab.confirm_order",{id:$scope.coupon_id});//跳转对应的优惠券详情页面//////////////////////////
                //隐藏登录入口
                $scope.no_login = false;
                //清除相关用户信息
                $scope.user_info.user_num = "";
                $scope.user_info.test_code = "";

                //记住密码（防止验证码登录后修改密码报错）
                $scope.id_pwd = {
                  user_num:mobile,
                  user_pwd:''
                };
                Storage.ls_set("user&pwd",$scope.id_pwd);//记住账号及密码

                $cordovaToast.show('登录成功!', 'long', 'center');
                break;
              case 10201:
                // alert("");
                $cordovaToast.show('验证码失效或错误!', 'long', 'center');
                break;
              case 10202:
                // alert("");
                $cordovaToast.show('该手机尚未注册', 'long', 'center');
                break;
              case 10203:
                // alert("");
                $cordovaToast.show('手机号已经被注册', 'long', 'center');
                break;
              case 10204:
                // alert("");
                $cordovaToast.show('手机号或者密码错误', 'long', 'center');
                break;
              default:
                // alert("");
                $cordovaToast.show('出错了，稍后再试', 'long', 'center');
            }
          })
        }else{//手机号错误
          $scope.test_code_tc = "请输入6位正确的验证码"
        }
      }else{//验证码未填或填错；
        $scope.phone_tc = "请输入正确的手机号码"
      }
    }
    //清除验证状态
    $scope.phone_test = function(){//手机号码状态清除
      $scope.phone_tc = " ";
      //账号密码登录状态
      $scope.reg_notice_phone = "";//手机号正则状态清除
      $scope.pwd_login_res = "";//登陆结果状态
    }
    $scope.verification_test = function(){//验证码状态清除
      $scope.test_code_tc = " ";
      //账号密码登录状态
      $scope.reg_notice_pwd = "";//pwd正则状态清除
      $scope.pwd_login_res = "";//登陆结果状态
    }

//账号密码登录
    $scope.n_user_info = {};
    $scope.login_pwd = function(){
      
      var p_user = $scope.n_user_info.user_num;
      var P_pwd = $scope.n_user_info.user_pwd;
      //正则验证；
      // var reg_pwd = /^[a-zA-Z]\w{5,17}$/;
      var reg_mobile = /^\d{5,}$/;

      if(reg_mobile.test(p_user)){//手机号验证通过
        if(P_pwd&&P_pwd.length>7){//密码正则通过
          $ionicLoading.show({
            template: '正在登录中...'
          });
          var md5_pwd = md5.createHash(P_pwd);
          // console.log(md5_pwd);
          //进行登录
          loginModule.n_login(p_user,md5_pwd).then(function(res){
            $ionicLoading.hide();
            // console.log("会员细信息："+JSON.stringify(res));
            switch(res.result){//10200 //请求成功!10201 // 验证码失效10202 // 该手机尚未注册!10203 // 手机号已经被注册10204 //手机号或者密码错误!
              case 10200:
                // alert("请求成功");
                //显示会员相关信息
                $scope.member_info = res.member;
                Storage.ls_set("user_infos",res.member);
                $scope.no_user_infos = false;//显示个人信息这块
                $scope.no_login = false//关闭登录入口
                //隐藏登录
                $scope.modal.hide();
                //$state.go("tab.confirm_order",{id:$scope.coupon_id});//跳转对应的优惠券详情页面//////////////////////////
                // 记住密码；
                if($scope.ischecked){
                  // alert("记住密码")
                  Storage.ls_set("user&pwd", $scope.n_user_info);//记住账号及密码
                }else{
                  Storage.ls_delete("user&pwd");//账号
                  // alert("删除密码")
                  $scope.n_user_info = {};//删除账号及密码
                }
                $cordovaToast.show('登录成功!', 'long', 'center');
                break;
              case 10201:
                // alert("验证码失效");
                $scope.pwd_login_res = "验证码失效或错误"
                break;
              case 10202:
                // alert("该手机尚未注册");
                $scope.pwd_login_res = "该手机尚未注册"
                break;
              case 10203:
                // alert("手机号已经被注册");
                $scope.pwd_login_res = "手机号已经被注册"
                break;
              case 10204:
                // alert("手机号或者密码错误");
                $scope.pwd_login_res = " 手机号或者密码错误"
                break;
              default:
                // alert("出错了，稍后再试");
                $scope.pwd_login_res = "出错了，稍后再试"
            }
           
          })
        }else{//密码正则未通过
           $scope.reg_notice_pwd = "数字和者字母（6到18位）"
        }
      }else{//手机号正则不通过
        $scope.reg_notice_phone = "手机号不正确"
      }

    }
  //获取或设置复选框是否选中
  $scope.ischecked = false;
  //点击切换显密码
  $scope.show_pwd_value = "显示"
  $scope.show_pwd = function(){
    var input = document.getElementById("pwd");
    if(input.type == "text"){
      console.log("pwd")
      input.type = "password";
      $scope.show_pwd_value = "显示"
    }else{
      console.log("text")
      input.type = "text";
      $scope.show_pwd_value = "隐藏"
    }

  }

   //注册模块
  $scope.register_info = {};//存放用户注册信息
  $scope.register = function(){
   
    //正则验证
    var r_mobile = $scope.register_info.phone
    var r_pwd = $scope.register_info.pwd;
    var r_code = $scope.register_info.code;
    var _mobile = /^\d{5,}$/.test(r_mobile);
    var _code = /\d{6}/.test(r_code);
    var area = document.getElementById('coupon_ZC_area').value;
    // alert(area);
    if(_mobile){
      if(r_pwd && r_pwd.length>7 ){
        if(_code){
          $ionicLoading.show({
            template: '正在注册中...'
          });
          var params = {
            m_phone : r_mobile,
            code : r_code ,
            m_pass : md5.createHash( r_pwd ),
            area:area
          };
          loginModule.register(params).then(function(res){
            // console.log("注册结果"+JSON.stringify(res));
            $ionicLoading.hide();
            switch(res.result){
              case 10200:
                // alert("注册成功,马上登录");
                $scope.change_page(0);//切换至登录模块
                $cordovaToast.show('注册成功,马上登录!', 'long', 'center');
                break;
              case 10201:
                $scope.r_pwd_login_res_code = "验证码失效或错误";
                break;
              case 10202:
                $scope.r_pwd_login_res = "该手机尚未注册";
                break;
              case 10203:
                $scope.r_pwd_login_res = "手机号已经被注册";
                break;
              case 10204:
                $scope.r_pwd_login_res = " 手机号或者密码错误";
                break;
              default:
                $scope.r_pwd_login_res = "出错了，稍后再试";
            }
          })
        }else{
          $ionicPopup.alert({
            title: '提示',
            template: '请输入6位数字验证码！'
          });
        }
      }else{
        // alert("密码为8位以上数字或字母")
        $scope.r_pwd_num = "密码为8位以上数字或字母"
      }
    }else{
      // alert("手机号码不正确")
      $scope.r_phone_num = "手机号码不正确"
    }
   
  }
  //清除注册提示状态
  $scope.hide_notice = function(){
    $scope.r_phone_num = "";
    $scope.r_pwd_num = "";
    $scope.r_pwd_login_res_code = "";
    $scope.r_pwd_login_res = "";
  }
  // 验证码(注册模块)
  $scope.register_code = function(e){
    var phone =  $scope.register_info.phone;
    var area = document.getElementById('coupon_ZC_area').value;
    // alert(area);
    // alert(phone);
    if ($scope.captcha.paraevent) {
      if (Common.checkMobile(phone)){
        $ionicLoading.show({
          template: '获取验证码...'
        });
        //调取验证码服务；
        loginModule.reg_captcha(phone,area).then(function(res){
          $ionicLoading.hide();
          // console.log(res);
          if(res.result == "10203"){
            $scope.r_pwd_login_res = "手机号已经注册，请直接登录";
          }else{
            Common.countDown($scope.captcha);
          }
        })
      }else{
        //手机号码不对；
      }
    } else {
        e.preventDefault();
    }
  }
  //重置验证码提示消息
  $scope.set_code_notice = function(){
     $scope.r_pwd_login_res = " "
  }
  //切换密码
  $scope.ischecked = true;//初始化为记住密码状态
  $scope.toggle_pwd = function(){
    if($scope.ischecked){
      $scope.ischecked = false;
    }else{
      $scope.ischecked = true;
    }
  }

})

//超值精选 、会员精选  确认订单
.controller('h_confirm_orderCtrl', function($cordovaToast,$stateParams,$scope,$ionicHistory,$cordovaToast,Storage,$ionicLoading,$state,mineModule){
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
   $scope.coupon_id = $stateParams.id;
  //  console.log("确认订单页面："+ $scope.coupon_id );
  //通过ID获取详情
  $scope.get_order = function(){
     var params = {
      goodsId:$scope.coupon_id
    }
    mineModule.http("getGoodDetail",params).then(function(res){
      console.log("确认订单："+JSON.stringify(res))
      if( res.code == 10000 ){
        $scope.coupons_details = res.info
        $scope.levelsNo = res.info.levelsNo;//商品的等级
        console.log("商品等级："+$scope.levelsNo);
        //商品数量的加减
			  $scope.max_count = $scope.coupons_details.memberSaleMaxNum;//限购的最大值
			  $scope.good_count = 1;//订单至少购买一件
			  $scope.price = $scope.coupons_details.payMoney//后台获取(单价)
			  $scope.inte = $scope.coupons_details.payPoint//后台获取（单个需要的积分）
			  //初始化显示计算金额（按一份来算）
			  $scope.Total_price = $scope.price;
			  $scope.Total_inte = $scope.inte*$scope.good_count ;
        
      }else{
        $cordovaToast.show('获取数据出错了...'+res.code, 'long', 'center');    
      }
    })
  }
  $scope.info = function(){
  	if(Storage.ls_get("user_infos")){
			var params = {
				memberUUID:JSON.parse(Storage.ls_get("user_infos")).memberuuid
	    }
	    mineModule.http("getMember",params).then(function(res){
	    	if(res.code = 10000){
	    		$scope.info = res.info
          // console.log("会员的积分信息："+JSON.stringify(res));
          $scope.card_name = res.info.levelNo;//获取会员当前的会员等级
          console.log("当前的会员等级："+$scope.card_name);
	    		$scope.all_inte =  res.info.usableBonus //后台获取（会员当前的总积分 ，购买商品的积分不能大于总积分）
	    	}else{
          $cordovaToast.show('获取数据出错了...'+res.code, 'long', 'center');
	    	}
	    
	    })
		}else{
      $cordovaToast.show('暂时未获取到会员信息，请重新登录再试', 'long', 'center');
		}
  }
  //获取订单详情；
  $scope.get_order() 
  //获取会员积分
	$scope.info();

  $scope.add = function(){
    if($scope.max_count > $scope.good_count){
    	$scope.good_count++;
	  	$scope.Total_price = ($scope.price*$scope.good_count).toFixed(2);
	    $scope.Total_inte = $scope.inte*$scope.good_count;
    }else{
			$cordovaToast.show('不能超过最大限购数!', 'long', 'center');
    }
  }
  $scope.reduce = function(){
    if( $scope.good_count > 1 ){
      $scope.good_count--;
     	$scope.Total_price = ($scope.price*$scope.good_count).toFixed(2);
      $scope.Total_inte = $scope.inte*$scope.good_count ;
    }else{
			$cordovaToast.show('至少兑换一件该商品!', 'long', 'center');
    }
  }

  //提交订单去支付
  $scope.go_pay = function(){
    //遮罩层；
    $ionicLoading.show({
      template: '努力获取订单中'
    });
    var h_AppTimer = setTimeout(function(){//超时30秒自动关闭遮罩层；
      $ionicLoading.hide();
      clearTimeout(h_AppTimer);
    },30000);
    //先判断用户等级是否能够兑换该物品；$scope.levelsNo商品等级
    if( $scope.levelsNo.indexOf($scope.card_name) != -1 ){//等级够可兑换；
      //再判断会员积分是否够用
      if( $scope.all_inte >= $scope.Total_inte ){//积分够用
        var obj = document.getElementsByName("pay")
        for(var i=0; i<obj.length; i ++){
          if(obj[i].checked){
            $scope.pay_value = obj[i].value;
          }
        }
        var order_params={
          "trade_name":$scope.coupons_details.couponInfo.couponName,//订单名字
          "trade_num":$scope.good_count,//订单数量
          "memberUUID":JSON.parse(Storage.ls_get("user_infos")).memberuuid,
          "member_id":JSON.parse(Storage.ls_get("user_infos")).m_id,
          "member_card":$scope.info.cardNo,
          "member_phone": $scope.info.mobile,
          "total_amount":parseFloat($scope.Total_price) ,   /////////////////////   记得后面的重新支付也要改（控制器：pay_resCtrl）；
          "total_point": $scope.Total_inte,
          "total_fee":parseFloat($scope.Total_price)*100,   ////////////////////////////  记得后面的重新支付也要改（控制器：pay_resCtrl）；
          "tradeDetails": [{
            "goodsid": $scope.coupon_id,
            "goodsnum": $scope.good_count,
            "goodsprice": $scope.price,
            "goodspoint": $scope.Total_inte
          }],
          "goodsList":[{
            "goodsId": $scope.coupon_id,
            "goodsName":$scope.coupons_details.couponInfo.couponName ,
            "price": $scope.price,
            "point": $scope.Total_inte,
            "goodsCount":$scope.good_count,
          }]
        }
        if( $scope.pay_value == "1"){//支付宝
  //			alert(JSON.stringify(order_params));
          mineModule.pay("aliPay",order_params).then(function(res){
            $ionicLoading.hide();//关闭遮罩层
            console.log("返回的订单信息："+JSON.stringify(res));
            if(res.code == 10200){//创建订单成功
              //区分0元支付   实际金额支付；
              var cc = res.out_trade_no;
              if(res.order){
                var html = res.order;
                cordova.plugins.alipay.payment(html,function(success){
                  $state.go("tab.h_pay_res",{id:"succ"+'.'+cc})
                }, function(error){
                  $cordovaToast.show(JSON.stringify(error), 'long', 'center');
                  // $state.go("tab.h_pay_res",{id:"erre"+'.'+html});//err
                  // Storage.ls_set("HTML",html);
                });
              }else{
                $ionicLoading.hide();
                $cordovaToast.show('购买成功~', 'long', 'center').then(function(succ){
                  $state.go("tab.h_pay_res",{id:"succ"+'.'+cc});
                });
              }
            }else if(res.code == 10403){// 超出最大限购
              $ionicLoading.hide();
              $cordovaToast.show('创建订单失败,您已经累计超过最大限购~', 'long', 'center');
            }else{//创建订单失败
              $ionicLoading.hide();
              $cordovaToast.show('创建订单失败!('+res.code+')', 'long', 'center')
            }
          
          })
        }else if( $scope.pay_value == "2" ){//微信
          // alert(2)
          mineModule.pay("wxPayAPP",order_params).then(function(res){
            $ionicLoading.hide();
            console.log("微信支付相关参数：" + JSON.stringify( res ) )
            if(res.code == 10200){//创建订单成功
              //区分0元支付   实际金额支付；
              var cc = res.out_trade_no;
              if(res.app_params){//唤起微信支付；
                var params ={
                  appid:res.app_params.appid, //appid
                  package :res.app_params.package,//Sign=WXPay
                  partnerid:res.app_params.partnerid, // merchant id
                  prepayid:res.app_params.prepayid, // prepay id
                  noncestr:res.app_params.noncestr, // nonce
                  timestamp:res.app_params.timestamp, // timestamp
                  sign:res.app_params.sign // signed string
                };
                  
                Wechat.sendPaymentRequest(params, function () {
                  $state.go("tab.h_pay_res",{id:"succ"+'.'+cc});
                }, function (reason) {
                  // $state.go("tab.h_pay_res",{id:"erre"+'.'+params});//err
                  // Storage.ls_set("WX_params",params);
                  $cordovaToast.show(reason, 'long', 'center')
                });
                
              }else{//0 元支付；
                $ionicLoading.hide();
                $cordovaToast.show('购买成功~', 'long', 'center').then(function(succ){
                  $state.go("tab.h_pay_res",{id:"succ"+'.'+cc});
                });
              }
            }else if(res.code == 10403){// 超出最大限购
              $ionicLoading.hide();
              $cordovaToast.show('创建订单失败,您已经累计超过最大限购~', 'long', 'center');
            }else{//创建订单失败
              $ionicLoading.hide();
              $cordovaToast.show('创建订单失败!('+res.code+')', 'long', 'center')
            }
          
          })

        }else{//既不是支付宝也不是微信
          $ionicLoading.hide();
          return;
        }
        
      }else{//积分不够用
        $ionicLoading.hide();//积分不够立即关闭遮罩层；
        $cordovaToast.show('您的积分不够!', 'long', 'center')
      }

    }else{//会员等级不够不予兑换
      $ionicLoading.hide();
  		$cordovaToast.show('您的会员等级暂时不能兑换该商品~', 'long', 'center')
    }

  }


})

//首页推送的支付结果 h_pay_resCtrl
.controller('h_pay_resCtrl', function(Storage,$scope,$ionicTabsDelegate,$ionicHistory,$location,$state,$stateParams){
  $scope.goback=function(){
    $ionicHistory.goBack();
    Storage.ls_delete("HTML");//点击返回删除之前存储；
  }
 	if($stateParams.id){//成功
// 	alert($stateParams.id.split(" ")[0]);
   	if($stateParams.id.split(".")[0] == "succ"){
	 		$scope.succ = true;
	 		$scope.err = false;
	 		$scope.id = $stateParams.id.split(".")[1];
//	 		alert("查看详情："+	$scope.id)
   	}
 		if($stateParams.id.split(".")[0] == "erre"){//支付失败
	 		$scope.succ = false;
	 		$scope.err = true;
//	 		$scope.re_pay = $stateParams.id.split(".")[1];
//	 		alert("重新支付："+$scope.re_pay)
	 	}
 	}
 	
 	
 	$scope.re_pay = function(){
    var HTML = Storage.ls_get("HTML");
    var WX_params  = Storage.ls_get("WX_params");
    if( HTML ){//取到支付宝支付
      cordova.plugins.alipay.payment(HTML,function(success){
        var aa = JSON.stringify(success).replace(/\\/g,"")
        var num = aa.indexOf("out_trade_no");
        var cc = aa.substring(num+15,num+51);
        $state.go("tab.h_pay_res",{id:"succ"+'.'+cc});
        Storage.ls_delete("HTML");//支付成功后删除之前的缓存
      }, function(error){
        $state.go("tab.h_pay_res",{id:"erre"+'.'+$scope.re_pay});//err
      });
    }else if( WX_params ){//取到微信支付
      params = JSON.parse( WX_params );
      alert("本地存储的数据："+ JSON.stringify(params));
      Wechat.sendPaymentRequest(params, function () {
        $state.go("tab.h_pay_res",{id:"succ"+'.'+cc});
      }, function (reason) {
        $state.go("tab.h_pay_res",{id:"erre"+'.'+params});//err
        Storage.ls_set("WX_params",params);
      });
    }

  } 

  //查看订单详情
  $scope.look_del = function(){
    //点击返回删除之前存储(支付宝/微信)；
    Storage.ls_delete("HTML");
    Storage.ls_delete("WX_params");
    $state.go("tab.home_order_del",{id:$scope.id});
  }
  //返回首页
  $scope.go_home = function(){
    //点击返回删除之前存储(支付宝/微信)；
    Storage.ls_delete("HTML");
    Storage.ls_delete("WX_params");
    $state.go("tab.home");
  }
  
})
//停车场；plateCtrl
.controller('plateCtrl', function($ionicLoading,$scope,$state,$stateParams,$ionicHistory,mineModule,Storage,$ionicPopup){
  $scope.goback=function(){
    $ionicHistory.goBack();
  }

  //获取会员的车牌信息
  $scope.get_member_plate = function(){
    if(Storage.ls_get("user_infos")){
      $ionicLoading.show({
        template: '努力加载中'
      });
      var params = {
        c_member_id:JSON.parse(Storage.ls_get("user_infos")).m_id
      }
      mineModule.park_serve("park",params).then(function(data){
        $ionicLoading.hide();
        console.log("获取到的会员车牌信息："+JSON.stringify(data));
        if(data.cars.length>0){
          $scope.m_plate = data.cars;
          for(var i = 0;i<$scope.m_plate.length;i++){
            if($scope.m_plate[i].inpark == 1){
               $scope.m_plate[i].isoutpark = false;
            }else{
               $scope.m_plate[i].isoutpark = true;
            }
          }
         
          //有车牌（隐藏灰色车牌）
          $scope.no_plate = false;
          if(data.cars.length<3){//显示添加车牌号链接
            $scope.hide_add_plate = true;
          }else{//关闭添加车牌号链接
            $scope.hide_add_plate = false;
          }
          $scope.hide_btn = false;//(隐藏编辑/取消按钮)
          $scope.show_edit = true;//初始化显示为编辑按钮
        }else if(data.resCode ==1){//未绑定车牌
          //没车牌（显示灰色车牌）
          $scope.no_plate = true;
          $scope.hide_btn = true;//(隐藏编辑/取消按钮)
          $scope.hide_add_plate = true;//显示绑定车牌入口
        }
       
      })

    }else{
      //暂未获取到用户信息
      $ionicPopup.alert({
        title: '提示！',
        template: '暂无用户信息，重新登录后再试！'
      });
    }
  }
  // $scope.get_member_plate();

  //点击编辑按钮功能（车牌出现删除按钮，编辑变为取消）
  $scope.show_delete = false;//初始化隐藏车牌删除按钮；
  $scope.do_edit = function(){
    //隐藏编辑按钮，显示取消按钮，
    $scope.show_edit = false;
    //显示车牌删除按钮
    $scope.show_delete = true;
  }
  $scope.do_cancel = function(){
     //隐藏车牌删除按钮
    $scope.show_delete = false;
    //显示编辑按钮
    $scope.show_edit = true;
  }

  //删除车牌的功能
  $scope.delete_plate = function(id , plate_number){
    $ionicPopup.confirm({
      title: '提示!', 
      template: '确定删除'+" "+ plate_number +'?'
    }).then(function(res) {
    if(res) {//点确定删除
      var params = {
        c_id:id
      }
      mineModule.park_serve("deleteCar ",params).then(function(res){
        console.log("删除车牌的结果:"+JSON.stringify(res));
        // {"result":"10200","message":"解绑成功!"}
        if(res.result == 10200){
          $scope.get_member_plate();
          $scope.do_cancel();//显示为"编辑“
          $ionicPopup.alert({
            title: '提示!',
            template: '删除成功！'
          });
        }else{
          $scope.do_cancel();//显示为"编辑“
          $ionicPopup.alert({
            title: '提示!',
            template: '删除失败!'
          });
        }
      })
      } else {//不点确定不删除
        return;
      }
    });
  } 

  $scope.$on('$ionicView.beforeEnter', function() { 
    //返回页面时初始化(编辑/取消)按钮;
    $scope.show_edit = true;
    $scope.show_delete = false;
    //初始化页面状态；
    $scope.get_member_plate();
  })

  //跳转绑定车牌页面；
  $scope.go_bind = function(){
    $state.go('tab.bind_plate')
  }


})



//停车场-》绑定车牌bind_plateCtrl
.controller('bind_plateCtrl', function($ionicLoading,$ionicPopup,$scope,$state,$stateParams,$ionicHistory,mineModule,Storage){
  $scope.goback=function(){
    $ionicHistory.goBack();
  }

  $scope.isen = false;
  $scope.member_plate_arr = [];//键盘选中的值放到数组里面
  $scope.member_plate = $scope.member_plate_arr.join("");//数组转化为字符串再前台显示

  //重构直接做字符串累加，不必用数组转换


  //tabs切换
  //初始化为机动车
  $scope.isnewenergy = false;
  $scope.tabs = function(x){
    if(x == 0){
      $scope.car_type = 1
      $scope.select = true;
      $scope.unselect = false;
      $scope.isnewenergy = false;//机动车
      if($scope.member_plate_arr.length>7){
        $scope.member_plate_arr.pop();
        $scope.member_plate = $scope.member_plate_arr.join("");//数组转化为字符串再前台显示
      }
    }else{
      $scope.car_type = 2;
      $scope.select = false ;
      $scope.unselect = true ;
      $scope.isnewenergy = true;//新能源
    }
  }
  $scope.tabs(0);
  //显示键盘
  $scope.show = function() {
   $scope.show_key_bord = true;
  };
  //关闭键盘
  $scope.close = function(){
    $scope.show_key_bord = false;
  }

  //自定义键盘数据
  $scope.zh_1 = ["京","沪","粤","津","冀","晋","蒙","辽","吉","黑"];
  $scope.zh_2 = ["苏","浙","皖","闽","赣","鲁","豫","鄂","湘","桂"];
  $scope.zh_3 = ["琼","渝","川","贵","云","藏","陕","甘","青","宁"];
  $scope.zh_4 = ["新","使","领","警","学","港","澳"];
  
  $scope.en_1 = ["1","2","3","4","5","6","7","8","9","0"];
  $scope.en_2 = ["Q","W","E","R","T","Y","U","I","O","P"];
  $scope.en_3 = ["A","S","D","F","G","H","J","K","L"];
  $scope.en_4 = ["Z","X","C","V","B","N","M"];

  
  $scope.toggle_keybord = function(){
    if($scope.isen == true){
      $scope.isen = false;
    }else{
      $scope.isen = true;
    }
  }

  //省点完后切换成英文键盘；
  $scope.Choose_zh = function(x){
    $scope.member_plate_arr.push(x);
    $scope.member_plate = $scope.member_plate_arr.join("");//数组转化为字符串再前台显示
    //切换键盘
    $scope.isen = true;
  }

  //键盘点击功能；
  $scope.Choose = function(x){
    console.log( $scope.isnewenergy );
    if($scope.isnewenergy == true){//新能源车
      if($scope.member_plate_arr.length < 8){
        $scope.member_plate_arr.push(x);
        $scope.member_plate = $scope.member_plate_arr.join("");//数组转化为字符串再前台显示
      }else{
        $scope.close();//关闭键盘
      }
    }else if($scope.isnewenergy == false){//不是新能源车  7位
      if($scope.member_plate_arr.length < 7){
        $scope.member_plate_arr.push(x);
        $scope.member_plate = $scope.member_plate_arr.join("");//数组转化为字符串再前台显示
      }else{
         $scope.close();//关闭键盘
      }
    }
    // $scope.member_plate_arr.push(x);
    // $scope.member_plate = $scope.member_plate_arr.join(" ");//数组转化为字符串再前台显示
  }
  //删除功能；
  $scope.delete = function(){
    //找到显示的字符串，依次从后往前删除;
    if($scope.member_plate_arr.length>0){
      $scope.member_plate_arr.pop();
      $scope.member_plate = $scope.member_plate_arr.join("");//数组转化为字符串再前台显示
    }
  }
  //添加车牌；
  $scope.sub_plate = function(){
    $ionicLoading.show({
      template: '提交车牌中'
    });
    //绑定车牌；addCar private int c_id;private String c_member_id;   //会员idprivate String c_member_car;  //车牌号private String c_member_type; //车辆类型
      if(Storage.ls_get("user_infos")){
        //机动车正则
        var JD_reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/;
        //新能源车牌；
        var NE_reg = /[\u4e00-\u9fa5][a-zA-Z](([DF](?![a-zA-Z0-9]*[IO])[0-9]{4})|([0-9]{5}[DF]))|^[冀豫云辽黑湘皖鲁苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼渝京津沪新京军空海北沈兰济南广成使领A-Z]{1}[a-zA-Z0-9]{5}[a-zA-Z0-9挂学警港澳]{1}$/;
        if($scope.isnewenergy == true){//新能源
          if($scope.member_plate_arr.length == 8){
            $scope.submite_myplate();
          }else{
            $ionicLoading.hide();//正则没过关闭loading状态
            $ionicPopup.alert({
              title: '提示!',
              template: '请输入正确的新能源车牌'
            });
          }
        }else if($scope.isnewenergy == false){//机动车
          if($scope.member_plate_arr.length == 7 ){
            $scope.submite_myplate();
          }else{
            $ionicLoading.hide();//正则没过关闭loading状态
            $ionicPopup.alert({
              title: '提示!',
              template: '请输入正确的机动车车牌'
            });
          }
        }
      }else{
        $ionicLoading.hide();//未登录关闭loading状态
        $ionicPopup.alert({
          title: '提示!',
          template: '请先登录后再试试'
        });
      }
    }

    //提交车牌业务；
    $scope.submite_myplate = function(){
      var params = {
        c_member_id:JSON.parse(Storage.ls_get("user_infos")).m_id,
        c_member_car:$scope.member_plate_arr.join(""),
        c_member_type:$scope.car_type//机动车的类型是1，新能源的类型是2；
      }
      // alert("提交参数："+JSON.stringify(params));
      mineModule.park_serve("addCar",params).then(function(res){
        console.log("绑定结果为："+JSON.stringify(res))
        if( res.result = 10200){
          $ionicLoading.hide();//添加成功后关闭loading状态
          $ionicPopup.alert({
            title: '提示',
            template: '绑定成功！'
          }).then(function(s){
            //清空输入；
            $scope.member_plate_arr = [];//键盘选中的值放到数组里面
            $scope.member_plate = $scope.member_plate_arr.join("");//数组转化为字符串再前台显示
            //提交成功后饭返回上一页
            $ionicHistory.goBack();

          })
        }
      })
    }
  

})




//停车场缴费 park_payeCtrl
.controller('park_payeCtrl', function($ionicLoading,$scope,$state,$stateParams,$ionicHistory,mineModule,Storage,$ionicPopup){
  $scope.goback=function(){
    $ionicHistory.goBack();
  }
  console.log("传过来的车牌ID："+$stateParams.id);
  //初始化默认会员积分为0
  $scope.integral = 0;

  //初始化显示优惠券列表
  $scope.isshowlist = true;
  $scope.isright = false;
  $scope.toggle_list = function(){
    if($scope.isshowlist == true){
      $scope.isshowlist = false;//不显示优惠券列表
      // 更改箭头反向为右边
      $scope.isright = true;
    }else{
      $scope.isshowlist = true;//显示优惠券列表
      //更改箭头方向为下边
      $scope.isright = false;
    }
  }
  //查询停车费
  $scope.get_cost = function(){
    // private String plateNo;//车牌号 （与条形码二选一)// private String barcode; //条形码 （与车牌号二选一)// private int freeMinutes;//免费时长 （分钟 ）// private float freeAmount; //免费金额（单位 :分）
    var params = {
      plateNo:$stateParams.id,//路由跳转传值过来
      freeMinutes:0,
      freeAmount:0
    }
    mineModule.park_serve_1("getParkingFree ",params).then(function(res){
      console.log("获取停车费的结果："+JSON.stringify(res));
      $scope.cost = res;
      $scope.pay_money = parseFloat( $scope.cost.result.unPayAmount )/100.00;
      if( parseFloat( $scope.cost.result.unPayAmount )/100 <= 0){//停车小于15分钟，未产生停车费用 隐藏积分抵扣跟券抵扣
        //隐藏核销
        $scope.isparkcoupon = false;//是否显示核销券
        $scope.isuseinte = false;//是否启用积分核销
        $scope.isshowlist = false; //点击箭头开关显示隐藏券列表
        $scope.is_opay = true;//是否零元支付（后台请求过来就是0元，不是核销后0元支付）
      }else{
        //显示核销
        $scope.isparkcoupon = true;//是否显示核销券
        $scope.isuseinte = true;//是否启用积分核销
        $scope.isshowlist = true;//点击箭头开关显示隐藏券列表
        $scope.is_opay = false;//是否零元支付（后台请求过来就是0元，不是核销后0元支付）
      }
      //保存后台传过来的最大抵扣积分，多少积分抵扣一小时	"parkpoint": "3000","hourpoint": "1000"
      $scope.max_use_inte = $scope.cost.parkingFree.parkpoint;//最多能抵扣多少积分；
      $scope.integral_to_hour = $scope.cost.parkingFree.hourpoint;//多少积分抵扣一个小时；
      //积分加
      $scope.offset_inte = 0;//抵消积分；
      $scope.step = parseInt($scope.integral_to_hour);//后台取
      $scope.max_offset = $scope.max_use_inte;//后台取3000
      //积分加法
      $scope.add_inte = function(){
        if(parseFloat($scope.pay_money) > 0){//应付金额必须大于0的时候才能操作积分抵扣；
          if(parseInt($scope.integral/parseInt($scope.integral_to_hour))*parseInt($scope.integral_to_hour) > $scope.offset_inte ){
            if($scope.offset_inte < $scope.max_offset){
              $scope.offset_inte =  $scope.offset_inte+1000;
              $scope.step =  $scope.step+1000;
              //计算积分抵现
              $scope.continue_to_pay();
            }else{
              //计算积分抵现
              $scope.continue_to_pay();
              $ionicPopup.alert({
                title: '提示!',
                template: '每天最多抵扣三小时！'
              });
            }
          }else{
            //计算积分抵现
            $scope.continue_to_pay();
            $ionicPopup.alert({
              title: '提示!',
              template: '再点积分就不够了，还需努力积分~'
            });
          }
        }else{
          $ionicPopup.alert({
            title: '提示!',
            template: '再点积分就浪费了~'
          });
        }
      }

    })

  }
  $scope.get_cost();

  //初始化显示停车优惠券为0张
  $scope.coupon_num = 0;
  if(Storage.ls_get("user_infos")){
    //获取停车优惠券(抵扣券)
    $scope.park_coupon = function(){//////////////////////////获取停车券；
      //getCoupon String page,String rows,String memberUUID,String type
      var params = {
        page:1,
        rows:50,
        memberUUID:JSON.parse(Storage.ls_get("user_infos")).memberuuid,
        type:1
      }
      mineModule.park_serve('getParkCoupon',params).then(function(res){
        console.log("获取的停车抵用券："+JSON.stringify(res))
        if(res.code == 10000){
          $scope.coupon_num = res.data.list.length;
            //组合优惠   优惠券复选框
            $scope.devList = res.data.list;
        }else{

        }
      })
    }
    $scope.park_coupon();

    $scope.available_coupon = [];//最多同时使用三张（核销数组）
    $scope.couponParkList = [];//提交订单用的数组（核销优惠券）
    $scope.choice_coupon = function(item){
      //每次选择优惠券先判断实际支付金额是不是大于0；
      // 大于0 可选一张，小于0，不可选 并隐藏积分抵扣选项
      // 若等于0，优惠券跟积分都不可选
      if(item.checked == true){
        // alert(parseFloat($scope.pay_money));alert(parseFloat(item.couponMoney));alert(parseFloat($scope.cost.parkingFree.basis)/2*(-1))
        // if(parseFloat($scope.pay_money) - parseFloat(item.couponMoney) >= parseFloat($scope.cost.parkingFree.basis)/2*(-1) ){// 结算金额-券金额  <= （-收费标准/2}
          // alert(2+"可jia")
          if( $scope.available_coupon.length < 3 ){
            $scope.available_coupon.push(item);
            console.log("选中的券："+JSON.stringify( $scope.available_coupon));
          }else{
            
            for(var i = 0 ;i< $scope.devList.length; i++){//设置前台当前点击的为非选中状态
              if($scope.devList[i].id == item.id){
                $scope.devList[i].checked = false;
              }
            }
            $ionicPopup.alert({
              title: '提示!',
              template: '最多可用三张抵用券！'
            });
          }
          $scope.continue_to_pay ()

        // }else{//多加的券不等选中，积分不能抵扣
        //   for(var i = 0 ;i< $scope.devList.length; i++){//设置前台当前点击的为非选中状态
        //     if($scope.devList[i].id == item.id){
        //       $scope.devList[i].checked = false;
        //     }
        //   }
        //     // alert(1 +"多加的券不等选中，积分不能抵扣")
        // }
        
      }else{//删除核销数组中取消选着的item
        for(var i = 0 ; i < $scope.available_coupon.length ; i++){
          if(item.id ==  $scope.available_coupon[i].id){
            $scope.available_coupon.splice(i,1) ;
          }
        }
        $scope.continue_to_pay ()
      }
     
    }

    //获取用户积分
    $scope.get_integral = function(){
      var phone = JSON.parse(Storage.ls_get("user_infos")).memberuuid;
      var params = {
        memberUUID:phone
      }
      mineModule.http("getMember",params).then(function(data){
        console.log("获取到的会员信息："+JSON.stringify(data));
        if(data.code = 10000){
          $scope.integral = data.info.usableBonus;//可用积分
          // 调试数据
          // $scope.integral = 2568;
        }else{
          $ionicPopup.alert({
            title: '提示',
            template: '获取信息出错了！'
          });
        }
      })
    }
    $scope.get_integral();

    //计算扣除抵用券跟积分后，还需支付多少钱；
    $scope.continue_to_pay = function(){
      //先算积分抵现 1000积分抵一个小时 一个小时停车费用后台传过来；
      $scope.inte_pay_sum = parseInt($scope.offset_inte/1000)*parseFloat($scope.cost.parkingFree.basis);
      // alert("积分抵现："+$scope.inte_pay_sum);
      //点击加积分抵扣的，判断还需支付是否大于0？显示优惠券抵扣：隐藏优惠券抵扣；
      // if(parseFloat($scope.cost.result.unPayAmount)/100 - $scope.inte_pay_sum > 0){
      //   $scope.isparkcoupon = true;
      //   $scope.isshowlist = true;
      // }else{
      //   $scope.isparkcoupon = false;
      //   $scope.isshowlist = true;
      // } 

      $scope.coupon_sum = 0 //优惠券抵现金
      for(var j = 0 ; j< $scope.available_coupon.length ; j++){
        // alert(JSON.stringify($scope.available_coupon[j]))
        $scope.coupon_sum += parseFloat($scope.available_coupon[j].couponMoney);
      }
      //在未选择积分的情况下
      if(parseInt($scope.offset_inte) < 1000){
        //勾选优惠券后做累加，判断还需支付是否大于0？显示积分抵扣：隐藏积分抵扣
        if(parseFloat($scope.cost.result.unPayAmount)/100 - $scope.coupon_sum > 0){
          $scope.isuseinte = true;
        }else{
          $scope.isuseinte = false;
        } 
      }
      
      // alert("优惠券抵现："+parseFloat($scope.coupon_sum ));

      //计算前台显示还需支付多少钱；
      $scope.pay_money = parseFloat($scope.cost.result.unPayAmount)/100 - $scope.inte_pay_sum - $scope.coupon_sum;
      if( $scope.pay_money <= 0){
        $scope.pay_money = 0 //前台显示0元
        $scope.payType = 0;
      }else{
        $scope.payType = 3;
      }
    }
    
    //初始化支付金额
  
    $scope.pay_now = function(){
      //点击支付开始时显示遮罩层
      $ionicLoading.show({template: '获取订单中，请稍后'});

      if( $scope.pay_money == 0){
        // alert($scope.pay_money)
        $scope.payType = 0;
      }else{
        // alert($scope.pay_money)
        $scope.payType = 3;
      }

      for( var i = 0 ;i <  $scope.available_coupon.length ; i++){
        var obj = {
          "couponId": $scope.available_coupon[i].id,             //优惠券id   
          "couponName": $scope.available_coupon[i].couponName,        //优惠券名称
          "couponType": $scope.available_coupon[i].couponType,                   //优惠券类型
          "couponPrice": $scope.available_coupon[i].couponMoney                  //优惠券价值
          }
          $scope.couponParkList.push(obj);       
      }
     
      // //获取定单详情：
      // if( $scope.sum_copon == null){ $scope.sum_copon = 0;}
      if( $scope.inte_pay_sum == null){  $scope.inte_pay_sum = 0;}
      var params = {
        "m_id": JSON.parse(Storage.ls_get("user_infos")).m_id,  //会员id                     
        "openid": JSON.parse(Storage.ls_get("user_infos")).openid, //openid
        "memberUUID": JSON.parse(Storage.ls_get("user_infos")).memberuuid,           //uuid
        "m_phone": JSON.parse(Storage.ls_get("user_infos")).m_phone,                //手机号
        "point": $scope.offset_inte ,                         //抵扣积分
        "point_amount": $scope.inte_pay_sum,                    //积分抵扣金额(元)
        "coupon_amount": $scope.coupon_sum,                   //优惠券抵扣金额(元)

        "amount": $scope.pay_money, 
        "total_fee":parseFloat($scope.pay_money)*100 ,                 //实际支付金额(元)(就是微信支付的金额)
        "deductionAmount":parseFloat($scope.inte_pay_sum)*100 +parseFloat($scope.coupon_sum)*100,//优惠总金额 (分) 比如停车和积分抵扣了30元  就是3000 分

        "feeId":$scope.cost.result.feeId,                 //停车场交易id
        "plateNo":$scope.cost.parkingFree.plateNo,                   //车牌号 
        "unPayAmount":$scope.cost.result.unPayAmount,                  //应该支付金额(元)
        "payType":$scope.payType,                         //支付方式(0：0元支付1：支付宝、2：银联、3：微信等)   (测试填写 3)
        "inparktime_s":$scope.cost.result.entryTime,       //入场时间
        "parktime":$scope.cost.result.parkingMinutes,                        //停车时间分钟
        "couponParkList":$scope.couponParkList
      }

       
      var obj = document.getElementsByName("pay")
			for(var i=0; i<obj.length; i ++){
        if(obj[i].checked){
          $scope.pay_value = obj[i].value;
        }
      }
      alert("支付参数："+JSON.stringify(params));
      if( $scope.pay_value == "1"){//启用支付宝支付
        mineModule.park_serve_1("aliPayParking",params).then(function(res){
          $scope.couponParkList.length = 0;//清空优惠券数组 
          $ionicLoading.hide();
          if( res.code == 10200){//验证通过
            if(res.payType == 0){//0 0元支付 1支付宝 3 微信
              //0元支付成功
              $ionicPopup.alert({
                title: '0元支付成功',
                template: '支付成功!您有15分钟的免费离场时间~'
              }).then(function(res){
                $ionicHistory.goBack();
              });
            }else{
              var html = res.order;
              console.log('支付宝相关参数：'+JSON.stringify(html));
              cordova.plugins.alipay.payment(html,function(success){//支付成功
                $ionicPopup.alert({
                  title: '支付成功!',
                  template: '您有15分钟的免费离场时间~'
                })
              }, function(error){//支付失败(支付失败/临时取消支付)
                $ionicPopup.alert({
                  title: '支付失败!',
                  template: '请您重新支付或线下离场支付~'
                })
              });
            }
            
          }else if(res.code == 10210){//前后台金额验证不匹配
            $ionicPopup.alert({
              title: '提示',
              template: '订单已超时，请重新获取~'
            }).then(function(){
              //重新获取停车费数据;
              $scope.get_cost();
            })
          }else{//其他错误
            $ionicPopup.alert({
              title: '提示',
              template: '出错了~ ('+res.code+')'
            })
          }

				})
      }else if($scope.pay_value == "2"){//启用微信支付
        mineModule.park_serve_1("wxPayParkingAPP",params).then(function(res){
          $scope.couponParkList.length = 0//清空优惠券数组
          $ionicLoading.hide();
          console.log("微信支付相关参数：" + JSON.stringify( res ) );
          if(res.code == 10200){
            if(res.payType == 0){//0 元支付
              $ionicPopup.alert({
                title: '0元支付成功',
                template: '支付成功!您有15分钟的免费离场时间~'
              }).then(function(res){
                $ionicHistory.goBack();
              });
            }else{
              var params ={
                appid:res.app_params.appid, //appid
                package :res.app_params.package,//Sign=WXPay
                partnerid:res.app_params.partnerid, // merchant id
                prepayid:res.app_params.prepayid, // prepay id
                noncestr:res.app_params.noncestr, // nonce
                timestamp:res.app_params.timestamp, // timestamp
                sign:res.app_params.sign // signed string
              };
              //启动微信APP支付；
              Wechat.sendPaymentRequest(params, function () {
                $ionicPopup.alert({
                  title: '支付成功!',
                  template: '您有15分钟的免费离场时间~'
                })
              }, function (reason) {
                $ionicPopup.alert({
                  title: '支付失败!',
                  template: '支付失败'+reason
                })
              });
            }
          }else if(res.code == 10210){
            $ionicPopup.alert({
              title: '提示',
              template: '订单已超时，请重新获取~'
            }).then(function(){
              //重新获取停车费数据;
              $scope.get_cost();
            })
          }else{
            $ionicPopup.alert({
              title: '提示',
              template: '出错了~ ('+res.code+')'
            })
          }
          // if(res.app_params){//唤起微信支付；
           
            
          // }else{//核销 0 元支付；
          //   $ionicLoading.hide();
          //   $cordovaToast.show('组合支付成功~', 'long', 'center').then(function(succ){
          //     //  $state.go("tab.h_pay_res",{id:"succ"+'.'+cc});
          //   });
          // }
				})
      }

    }
  }else{
    $ionicPopup.alert({
      title: '提示',
      template: '请重新登录后再试试！'
    });
  }
  
  //积分减
  $scope.reduce_inte = function(){
    if($scope.offset_inte>=1000){
      $scope.offset_inte = $scope.offset_inte-1000;
      $scope.step =  $scope.step-1000;
      //计算积分抵现
      $scope.continue_to_pay();
    }else{
      //计算积分抵现
      $scope.continue_to_pay();
      $scope.offset_inte = 0;
      $ionicPopup.alert({
        title: '提示!',
        template: '抵扣不能小于0！'
      });
      
    }
  }


})

//首页 - 积分展示页面（详情）
.controller('h_integralCtrl',  function(Storage,$ionicPopup,$ionicScrollDelegate,mineModule,$ionicHistory,$scope,Common,$state,$timeout) {
  $scope.goback=function(){
      $ionicHistory.goBack();
  }

 
  //获取积分 详情getPoint m_id=10 record  (0 当月 , 1 上月 2上上月 以此类推)
  if(Storage.ls_get("user_infos")){
    
    $scope.moredata = true;//初始化下拉加载
    $scope.nomoreData = false;
    
    $scope.id = JSON.parse(Storage.ls_get("user_infos")).memberuuid;//通过id 获取用户在用的手机号（即账户）
    // 获取积分列表
    $scope.get_list_params = {
      memberUUID: $scope.id,
      page:1,
      rows:100
    }
    
    $scope.get_inte_list = function(){
      mineModule.http("getPointRecord",$scope.get_list_params).then(function(res){
      // console.log("积分："+JSON.stringify(res))
        if(res.code == 10000){//获取数据succ
          $scope.data = res.data.list; 
          $scope.month = res.data.monthsTotal;
          $scope.integral = res.data.pointTotal.pointBalance//当前积分；
          // console.log("积分列表:"+JSON.stringify($scope.data))
          if( $scope.data && $scope.month){
            for( var i = 0 ; i <  $scope.month.length ; i++ ){
              $scope.month[i].list = [];//每个月份追加列表的属性；
              for( var j = 0 ; j < $scope.data.length ; j++){
                if( $scope.month[i].month.slice(0,4) == $scope.data[j].dateTime.slice(0,4) && $scope.month[i].month.slice(5,7) == $scope.data[j].dateTime.slice(5,7)){
                  $scope.month[i].list.push($scope.data[j]);//每个月份列表的属性 添加对应的值
                }
              }
            }
            $scope.new_data = $scope.month;
          }
          
        }else{//获取积分列表出错了
          $ionicPopup.alert({
            title: '出错了',
            template: '获取积分出错了，稍后再试~'
          });
        }
      })
    }
    
    $scope.get_inte_list();//正常订单
  
    // $scope.loadMore = function () {
    //     // console.log("检测到上拉事件")
    //     $scope.get_list_params.record++;
    //     var timer = null;
    //     mineModule.http("getPoint", $scope.get_list_params).then(function (res) {
    //         $scope.res = res.tradeList;
    //         console.log("下拉加载数据：" +JSON.stringify($scope.res));
    //         if ( $scope.res) {
    //             if ( $scope.res.length !== 0) {
    //                 for (var i = 0; i < $scope.res.length; i++) {
    //                     $scope.data.tradeList.push($scope.res[i]);
    //                 }
    //             }
    //             if ( $scope.res.length === 0) {
    //                 $scope.moredata = false;
    //                 $scope.nomoreData = true;
    //             }
    //             timer = $timeout(function () {
    //                 $scope.$broadcast('scroll.infiniteScrollComplete');
    //             }, 1500);
    //         }else{
    //             $scope.moredata = false;
    //             $scope.nomoreData = true;
    //             $scope.$broadcast('scroll.infiniteScrollComplete');
    //         }
    //     })
    // };


  }else{
    alert('请退出再登录试试！');
  }
  
})
//停车场过滤器
.filter('platenumber', function() { //可以注入依赖
  return function(text) {
      return "共"+text+"辆";
  }
})
//停车券的数量
.filter('p_c_num', function() { //可以注入依赖
  return function(text) {
      return "共"+text+"张停车券";
  }
})
//应付金额
.filter('unPayAmount', function() { //可以注入依赖
  return function(text) {
      return text/100+"元";
  }
})
//停车时间
.filter('parkingMinutes', function() { //可以注入依赖
  return function(text) {
    if(text < 60 ){
      return text+"分钟";
    }else{
      var h = parseInt(text/60);
      var m = text - h*60;
      if(m != 0){
        return  h+"小时"+m+"分钟";
      }else{
        return  h+"小时整";
      }
    }
  }
})
//收费标准；
.filter('basis', function() { //可以注入依赖
  return function(text) {
    return  text+"元/每小时";
  }
})


//超值精选、超值精选 、会员精选    支付状态
.controller('workingCtrl', function($scope,$state,$stateParams,$ionicHistory,homeModule){
  $scope.goback=function(){
    $ionicHistory.goBack();
  }


})

//开发中
.controller('workingCtrl', function($scope,$state,$stateParams,$ionicHistory,homeModule){
  $scope.goback=function(){
    $ionicHistory.goBack();
  }


})